package com.smart.campus.controller;


import com.smart.campus.dto.DangerDetails;
import com.smart.campus.dto.HiddenDanger;
import com.smart.campus.pojo.PagedResponse;
import com.smart.campus.pojo.ResponseResult;
import com.smart.campus.service.DangerServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "隐患管理模块")
@CrossOrigin
@RestController
@RequestMapping(value = "danger")
public class DangerController {

    @Autowired
    private DangerServiceFeign dangerServiceFeign;

    @ApiOperation(value = "隐患列表分页查询",httpMethod = "POST",notes = "隐患列表分页查询")
    @RequestMapping(value = "findDangerPagination")
    public ResponseResult<PagedResponse<HiddenDanger>> findDangerPagination(@RequestBody HiddenDanger hiddenDanger, @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        return new ResponseResult<>(200,"隐患列表分页查询成功",dangerServiceFeign.findDangerPagination(hiddenDanger,pageNum,pageSize));
    }

    @ApiOperation(value = "上报隐患",httpMethod = "POST",notes = "上报隐患")
    @RequestMapping(value = "addDanger")
    public ResponseResult addDanger(@RequestBody HiddenDanger hiddenDanger){
        try {
            dangerServiceFeign.addDanger(hiddenDanger);
            return new ResponseResult<>(200,"上报隐患成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"上报隐患失败");
        }
    }

    @ApiOperation(value = "查看隐患详情",httpMethod = "POST",notes = "查看隐患详情")
    @RequestMapping(value = "getDangerById")
    public ResponseResult<HiddenDanger> getDangerById(Long id){
        return new ResponseResult<>(200,"根据隐患id获取隐患详情成功",dangerServiceFeign.getDangerById(id));
    }

    @ApiOperation(value = "指派人员处理隐患",httpMethod = "POST",notes = "指派人员处理隐患")
    @RequestMapping(value = "assignPersonnelDanger")
    public ResponseResult assignPersonnelDanger(@RequestBody DangerDetails dangerDetails){
        try {
            dangerServiceFeign.assignPersonnelDanger(dangerDetails);
            return new ResponseResult<>(200,"指派成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"指派失败");
        }
    }
}
